/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package stuff.web;

import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMethod;
import static org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.*;

/**
 *
 * @author Николай
 */
@Controller
public class LoginCntrl {

    private final static String name_key = SPRING_SECURITY_LAST_USERNAME_KEY;

    @RequestMapping(value = "/account/login")
    public String loginHandler() {
        return "/singleLogin";
    }

    @RequestMapping(value = "/account/loginfailure", method = RequestMethod.GET)
    public String setForm(
            Model model,
            HttpServletRequest req) {
        String name = (String) req.getSession().getAttribute(name_key);
        model.addAttribute("userName", (name != null) ? name : name);
        return "/index";
    }
}
